@ibiz-template-plugin/ibiz-file-previewer 0.0.8 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.es.js CHANGED
@@ -958,8 +958,8 @@ var EngineType = /* @__PURE__ */ ((EngineType2) => {
958
958
  })(EngineType || {});
959
959
  const FileTypeEngineMap = /* @__PURE__ */ new Map([
960
960
  ["html", [
961
- "MD"
962
- /* MD */
961
+ "HTML"
962
+ /* HTML */
963
963
  ]],
964
964
  // HTML类型文件
965
965
  ["md", [
@@ -1190,18 +1190,16 @@ function u(e2, t2, n2, o2, i2, u2) {
1190
1190
  return l$3.vnode && l$3.vnode(l2), l2;
1191
1191
  }
1192
1192
  const FilePreviewHtml = (props) => {
1193
+ const containerRef = A(null);
1193
1194
  y$1(() => {
1195
+ if (containerRef.current) {
1196
+ const shadowRoot = containerRef.current.attachShadow({ mode: "open" });
1197
+ const content = '\n <style>\n .content-container {\n height: 100%;\n width: 100%;\n }\n </style>\n <div class="content-container">\n '.concat(props.controller.state.value.content, "\n </div>\n ");
1198
+ shadowRoot.innerHTML = content;
1199
+ }
1194
1200
  props.onInitialization();
1195
1201
  }, []);
1196
- return /* @__PURE__ */ u("div", { className: "file-preview-html ".concat(props.controller.state.value.theme), children: /* @__PURE__ */ u(
1197
- "div",
1198
- {
1199
- className: "container",
1200
- dangerouslySetInnerHTML: {
1201
- __html: props.controller.state.value.content
1202
- }
1203
- }
1204
- ) });
1202
+ return /* @__PURE__ */ u("div", { className: "file-preview-html ".concat(props.controller.state.value.theme), children: /* @__PURE__ */ u("div", { ref: containerRef, className: "container" }) });
1205
1203
  };
1206
1204
  const ZoomOutSvg = () => {
1207
1205
  return /* @__PURE__ */ u(
@@ -18412,7 +18410,7 @@ const ImagePage = (props) => {
18412
18410
  let result = {};
18413
18411
  if (isLoading.value) {
18414
18412
  result = {
18415
- height: "".concat(parentStyle.value.height, "px"),
18413
+ height: "".concat(parentStyle.value.height * props.state.value.scale, "px"),
18416
18414
  flexShrink: 0
18417
18415
  };
18418
18416
  } else {
@@ -18452,28 +18450,15 @@ const ImagePage = (props) => {
18452
18450
  width: rect.width
18453
18451
  };
18454
18452
  };
18455
- const emitImageStyle = () => {
18456
- if (!imgRef.current) {
18457
- return;
18458
- }
18459
- const rect = imgRef.current.getBoundingClientRect();
18460
- if (!rect) return;
18461
- if (rect.height) {
18462
- props.onSizeChange(rect.height);
18463
- }
18464
- };
18465
18453
  y$1(() => {
18466
18454
  updateParentStyle();
18467
18455
  const observer = new ResizeObserver(updateParentStyle);
18468
- const imgObserver = new ResizeObserver(emitImageStyle);
18469
18456
  if (imgRef.current) {
18470
- imgObserver.observe(imgRef.current);
18471
18457
  if (imgRef.current.parentElement) {
18472
18458
  observer.observe(imgRef.current.parentElement);
18473
18459
  }
18474
18460
  }
18475
18461
  return () => {
18476
- imgObserver.disconnect();
18477
18462
  observer.disconnect();
18478
18463
  };
18479
18464
  }, []);
@@ -18485,7 +18470,7 @@ const ImagePage = (props) => {
18485
18470
  style: imgStyle.value,
18486
18471
  "data-page-index": props.index,
18487
18472
  children: [
18488
- /* @__PURE__ */ u(
18473
+ props.isShowImage ? /* @__PURE__ */ u(
18489
18474
  "img",
18490
18475
  {
18491
18476
  className: "image-content",
@@ -18499,7 +18484,7 @@ const ImagePage = (props) => {
18499
18484
  },
18500
18485
  loading: "lazy"
18501
18486
  }
18502
- ),
18487
+ ) : /* @__PURE__ */ u(Loading, {}),
18503
18488
  isLoading.value && /* @__PURE__ */ u(Loading, {})
18504
18489
  ]
18505
18490
  }
@@ -18511,8 +18496,7 @@ const FilePreviewImageGroup = (props) => {
18511
18496
  const contentRef = A(null);
18512
18497
  const isScrolling = useSignal(false);
18513
18498
  const [loadedPages, setLoadedPages] = d$2(/* @__PURE__ */ new Set());
18514
- const imgContainerHeight = useSignal(0);
18515
- const handleScroll = throttle(() => {
18499
+ const computeClosestPage = () => {
18516
18500
  if (contentRef.current) {
18517
18501
  const containerRect = contentRef.current.getBoundingClientRect();
18518
18502
  let closestPage = state.value.currentPage;
@@ -18530,11 +18514,27 @@ const FilePreviewImageGroup = (props) => {
18530
18514
  }
18531
18515
  }
18532
18516
  });
18517
+ return closestPage;
18518
+ }
18519
+ };
18520
+ const handleScroll = throttle(() => {
18521
+ if (contentRef.current) {
18522
+ const closestPage = computeClosestPage();
18533
18523
  if (!isScrolling.value && closestPage !== state.value.currentPage) {
18534
18524
  controller.updateState({ currentPage: closestPage });
18535
18525
  }
18536
18526
  }
18537
18527
  }, 100);
18528
+ const handleImageResize = () => {
18529
+ if (contentRef.current) {
18530
+ setTimeout(() => {
18531
+ const closestPage = computeClosestPage();
18532
+ if (closestPage !== state.value.currentPage) {
18533
+ controller.updateState({ currentPage: closestPage });
18534
+ }
18535
+ }, 0);
18536
+ }
18537
+ };
18538
18538
  const scrollToPage = (pageIndex) => {
18539
18539
  if (contentRef.current) {
18540
18540
  const pageElement = contentRef.current.querySelector(
@@ -18554,14 +18554,17 @@ const FilePreviewImageGroup = (props) => {
18554
18554
  }
18555
18555
  });
18556
18556
  };
18557
- const handlePageClick = (pageIndex) => {
18558
- controller.updateState({ currentPage: pageIndex });
18559
- scrollToPage(pageIndex);
18557
+ const updateIsScrolling = () => {
18560
18558
  isScrolling.value = true;
18561
18559
  setTimeout(() => {
18562
18560
  isScrolling.value = false;
18563
18561
  }, 1e3);
18564
18562
  };
18563
+ const handlePageClick = (pageIndex) => {
18564
+ controller.updateState({ currentPage: pageIndex });
18565
+ scrollToPage(pageIndex);
18566
+ updateIsScrolling();
18567
+ };
18565
18568
  const handleInput = (e2) => {
18566
18569
  const target = e2.target;
18567
18570
  const newPage = parseInt(target.value) - 1;
@@ -18588,10 +18591,10 @@ const FilePreviewImageGroup = (props) => {
18588
18591
  const handleModeChange = (payload) => {
18589
18592
  const value = payload.target.value;
18590
18593
  controller.switchMode(value);
18594
+ scrollToPage(state.value.currentPage);
18591
18595
  };
18592
18596
  y$1(() => {
18593
18597
  if (contentRef.current) {
18594
- imgContainerHeight.value = contentRef.current.clientHeight;
18595
18598
  contentRef.current.addEventListener("scroll", handleScroll);
18596
18599
  }
18597
18600
  preloadImages();
@@ -18646,30 +18649,15 @@ const FilePreviewImageGroup = (props) => {
18646
18649
  setLoadedPages((prev) => new Set(prev).add(index));
18647
18650
  }
18648
18651
  }
18649
- return shouldRender || shouldKeepLoaded ? /* @__PURE__ */ u(
18652
+ return /* @__PURE__ */ u(
18650
18653
  ImagePage,
18651
18654
  {
18652
18655
  page,
18653
18656
  index,
18654
18657
  state,
18655
- onSizeChange: (height) => {
18656
- imgContainerHeight.value = height;
18657
- }
18658
+ isShowImage: shouldRender || shouldKeepLoaded
18658
18659
  },
18659
18660
  index
18660
- ) : (
18661
- // 渲染占位元素,保持布局结构
18662
- /* @__PURE__ */ u(
18663
- "div",
18664
- {
18665
- "data-page-index": index,
18666
- style: {
18667
- height: "".concat(imgContainerHeight, "px"),
18668
- flexShrink: 0
18669
- }
18670
- },
18671
- index
18672
- )
18673
18661
  );
18674
18662
  })
18675
18663
  }
@@ -18735,8 +18723,13 @@ const FilePreviewImageGroup = (props) => {
18735
18723
  value: state.value.currentPage + 1,
18736
18724
  min: "1",
18737
18725
  max: state.value.total || 1,
18738
- onInput: (event) => {
18726
+ onBlur: (event) => {
18739
18727
  handleInput(event);
18728
+ },
18729
+ onKeyDown: (event) => {
18730
+ if (event.key === "Enter") {
18731
+ handleInput(event);
18732
+ }
18740
18733
  }
18741
18734
  }
18742
18735
  ),
@@ -18769,6 +18762,7 @@ const FilePreviewImageGroup = (props) => {
18769
18762
  className: "control-btn",
18770
18763
  onClick: (event) => {
18771
18764
  controller.zoomOutPreview(event);
18765
+ handleImageResize();
18772
18766
  },
18773
18767
  children: /* @__PURE__ */ u("span", { className: "icon", children: /* @__PURE__ */ u(ZoomOutSvg, {}) })
18774
18768
  }
@@ -18784,6 +18778,7 @@ const FilePreviewImageGroup = (props) => {
18784
18778
  className: "control-btn",
18785
18779
  onClick: (event) => {
18786
18780
  controller.zoomInPreview(event);
18781
+ handleImageResize();
18787
18782
  },
18788
18783
  children: /* @__PURE__ */ u("span", { className: "icon", children: /* @__PURE__ */ u(ZoomInSvg, {}) })
18789
18784
  }
@@ -18796,6 +18791,7 @@ const FilePreviewImageGroup = (props) => {
18796
18791
  className: "control-btn",
18797
18792
  onClick: () => {
18798
18793
  controller.reSet();
18794
+ handleImageResize();
18799
18795
  },
18800
18796
  children: /* @__PURE__ */ u("span", { className: "icon", children: /* @__PURE__ */ u(ResetSvg, {}) })
18801
18797
  }
@@ -19048,7 +19044,7 @@ class FilePreviewImageController extends FilePreviewItemController {
19048
19044
  zoomOutPreview(_event) {
19049
19045
  const { scale } = this.state.value;
19050
19046
  this.updateState({
19051
- scale: Math.max(scale - 0.1, 0.1)
19047
+ scale: Math.max(scale - 0.1, 0.5)
19052
19048
  });
19053
19049
  }
19054
19050
  /**
@@ -19931,6 +19927,19 @@ class FilePreviewMDController extends FilePreviewTextController {
19931
19927
  }
19932
19928
  }
19933
19929
  class FilePreviewHtmlController extends FilePreviewTextController {
19930
+ /**
19931
+ * 获取内容
19932
+ */
19933
+ async getContent() {
19934
+ const options = this.filePreviewShell.getOptions();
19935
+ const { fileId, fileCat } = this.filePreviewShell.getState();
19936
+ try {
19937
+ const content = await options.getContent(fileId, "html", fileCat);
19938
+ return content || "";
19939
+ } catch (error2) {
19940
+ return error2.message || "";
19941
+ }
19942
+ }
19934
19943
  }
19935
19944
  class FilePreviewItemDispatcher {
19936
19945
  /**